package com.dhcc.DRGsHosp.core.domain;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.openkoala.koala.commons.domain.KoalaLegacyEntity;
import org.springframework.util.StringUtils;

/**
 * @title		:Department.java
 * @description	:科室
 * @author		:mazhaoyan
 * @date		:2015年4月2日
 * @version     :1.0
 * @copyright   :DHCC 2013-2014 
 */
@Entity
@Table(name="T_DEPARTMENT", schema = "DRGs")
@NamedQueries({
    @NamedQuery(name = "Department.findDepartmentByCode", query = "SELECT _dep FROM Department _dep WHERE _dep.depCode = :depCode "),
    @NamedQuery(name = "Department.findDepCodeByName", query = "SELECT _dep.depCode FROM Department _dep where _dep.depName = :depName"),
    @NamedQuery(name = "Department.findDepNameByCode", query = "SELECT _dep.depName FROM Department _dep where _dep.depCode = :depCode")
})
public class Department extends KoalaLegacyEntity {

	private static final long serialVersionUID = 8544756925846780247L;
	
	/**
	 * 空构造函数
	 */
	public Department() {
		super();
	}
	
	/**
	 * @param depCode 科室代码
	 * @param parDepGroupCode Par专业组组代码
	 * @param parDepStageCode Par分段管理科室代码
	 * @param parHospCode Par医院代码
	 * @param depName 科室名称
	 * @param depType 科室类型
	 * @param depTelephone 科室电话
	 * @param depLeader 科室负责人
	 * @param validStates 有效状态
	 * @param depOrder 显示顺序
	 * @param depHis his科室名称
	 * @param depBedCnt 科室床位数
	 * @param depDoctorCnt 科室医生数
	 * @param depHisCode his科室代码
	 */
	public Department(String depCode, String parDepGroupCode,
			String parDepStageCode, String parHospCode, String depName,
			String depType, String depTelephone, String depLeader,
			String validStates, Double depOrder, String depHis,
			Double depBedCnt, Double depDoctorCnt, Double isOpeDep,
			String depGroupDesc,String depHisCode) {
		super();
		this.depCode = depCode;
		this.parDepGroupCode = parDepGroupCode;
		this.parDepStageCode = parDepStageCode;
		this.parHospCode = parHospCode;
		this.depName = depName;
		this.depType = depType;
		this.depTelephone = depTelephone;
		this.depLeader = depLeader;
		this.validStates = validStates;
		this.depOrder = depOrder;
		this.depHis = depHis;
		this.depBedCnt = depBedCnt;
		this.depDoctorCnt = depDoctorCnt;
		this.isOpeDep = isOpeDep;
		this.depGroupDesc = depGroupDesc;
		this.depHisCode = depHisCode;
	}
	public Department(String depCode, String parDepGroupCode, String depName,String depHisCode,String depHis,
			String depTelephone, String depLeader, String validStates,Double depOrder,
			Double depBedCnt, Double depDoctorCnt,Double isOpeDep,String parHospCode,String depType) {
		super();
		this.depCode = depCode;
		this.parDepGroupCode = parDepGroupCode;
		this.depName = depName;
		this.depHisCode = depHisCode;
		this.depHis = depHis;
		this.depTelephone = depTelephone;
		this.depLeader = depLeader;
		this.validStates = validStates;
		this.depOrder = depOrder;
		this.depBedCnt = depBedCnt;
		this.depDoctorCnt = depDoctorCnt;
		this.isOpeDep = isOpeDep;
		this.parHospCode=parHospCode;
		this.depType=depType;
	}
	/**
	 * @param depCode
	 * @param parDepGroupCode
	 * @param depName
	 * @param depTelephone
	 * @param depLeader
	 * @param validStates
	 * @param depOrder
	 * @param depBedCnt
	 * @param depDoctorCnt
	 * @param depGroupDesc
	 */
	public Department(String depCode, String parDepGroupCode, String depName,
			String depTelephone, String depLeader, String validStates,Double depOrder,
			Double depBedCnt, Double depDoctorCnt,Double isOpeDep,String parHospCode) {
		super();
		this.depCode = depCode;
		this.parDepGroupCode = parDepGroupCode;
		this.depName = depName;
		this.depTelephone = depTelephone;
		this.depLeader = depLeader;
		this.validStates = validStates;
		this.depOrder = depOrder;
		this.depBedCnt = depBedCnt;
		this.depDoctorCnt = depDoctorCnt;
		this.isOpeDep = isOpeDep;
		this.parHospCode=parHospCode;
	}
	
	public Department(String depCode, String depName) {
		super();
		this.depCode = depCode;
		this.depName = depName;
	}
	
	public Department(String depCode) {
		super();
		this.depCode = depCode;
	}

	/**
	 * @methodname    :getBy
	 * @description   : 通过科室代码查询科室信息
	 * @param         :
	 * @author        :lileizheng
	 * @return        :
	 * @date          :2015年5月12日
	 */
	public static <T extends Department> T getBy(String depCode) {
		if(!StringUtils.hasLength(depCode)){
			depCode = "";
		}
		return getRepository()
                .createNamedQuery("Department.findDepartmentByCode")
                .addParameter("depCode", depCode)
                .singleResult();
	}

	//科室代码
	@Id
	@Column(name = "DEP_CODE",nullable=false)
	private String depCode;
	
	//Par专业组组代码
	@Column(name = "PARDEPGROUP_CODE")
	private String parDepGroupCode;
	
	//Par分段管理科室代码
	@Column(name = "PARDEP_STAGE_CODE")
	private String parDepStageCode;
	
	//Par医院代码
	@Column(name = "PARHOSP_CODE")
	private String parHospCode;
	
	//科室名称
	@Column(name = "DEP_NAME",nullable=false)
	private String depName;
	
	//科室类型
	@Column(name = "DEP_TYPE")
	private String depType;
	
	//科室电话
	@Column(name = "DEP_TELEPHONE")
	private String depTelephone;
	
	//科室负责人
	@Column(name = "DEP_LEADER")
	private String depLeader;
	
	//有效状态
	@Column(name = "VALID_STATES")
	private String validStates;
	
	//显示顺序
	@Column(name = "DEP_ORDER",nullable=false)
	private Double depOrder;
	
	//his科室名称
	@Column(name = "DEP_HIS")
	private String depHis;
	
	//科室床位数
	@Column(name = "DEP_BED_CNT")
	private Double depBedCnt;
	
	//科室医生数
	@Column(name = "DEP_DOCTOR_CNT")
	private Double depDoctorCnt;
	//是否手术科室
	@Column(name = "IS_OPE_DEP")
	private Double isOpeDep;
	
	//his科室代码
	@Column(name = "DEP_HIS_CODE")
	private String depHisCode;
	
	//科室病房
	@Column(name = "DEP_WARD")
	private String depWard;
	
	//临床专业
	@Column(name = "SPEC_CODE")
	private String specCode;
	
	// 覆盖的DRG数量
	@Transient
	private Integer countDRG;

	public String getSpecCode() {
		return specCode;
	}

	public void setSpecCode(String specCode) {
		this.specCode = specCode;
	}

	//科室组名称
	@Transient
	private String depGroupDesc;

	public String getDepGroupDesc() {
		return depGroupDesc;
	}

	public void setDepGroupDesc(String depGroupDesc) {
		this.depGroupDesc = depGroupDesc;
	}
	//院区代码描述
	@Transient
	private String hospDesc;
	
	public String getHospDesc() {
		return hospDesc;
	}

	public void setHospDesc(String hospDesc) {
		this.hospDesc = hospDesc;
	}

	public String getDepCode() {
		return depCode;
	}

	public void setDepCode(String depCode) {
		this.depCode = depCode;
	}

	public String getParDepGroupCode() {
		return parDepGroupCode;
	}

	public void setParDepGroupCode(String parDepGroupCode) {
		this.parDepGroupCode = parDepGroupCode;
	}

	public String getParDepStageCode() {
		return parDepStageCode;
	}

	public void setParDepStageCode(String parDepStageCode) {
		this.parDepStageCode = parDepStageCode;
	}

	public String getParHospCode() {
		return parHospCode;
	}

	public String getDepWard() {
		return depWard;
	}

	public void setDepWard(String depWard) {
		this.depWard = depWard;
	}

	public void setParHospCode(String parHospCode) {
		this.parHospCode = parHospCode;
	}

	public String getDepName() {
		return depName;
	}

	public void setDepName(String depName) {
		this.depName = depName;
	}

	public String getDepType() {
		return depType;
	}

	public void setDepType(String depType) {
		this.depType = depType;
	}

	public String getDepTelephone() {
		return depTelephone;
	}

	public void setDepTelephone(String depTelephone) {
		this.depTelephone = depTelephone;
	}

	public String getDepLeader() {
		return depLeader;
	}

	public void setDepLeader(String depLeader) {
		this.depLeader = depLeader;
	}

	public String getValidStates() {
		return validStates;
	}

	public void setValidStates(String validStates) {
		this.validStates = validStates;
	}
	
	public Double getDepOrder() {
		return depOrder;
	}

	public void setDepOrder(Double depOrder) {
		this.depOrder = depOrder;
	}

	public String getDepHis() {
		return depHis;
	}

	public void setDepHis(String depHis) {
		this.depHis = depHis;
	}

	public Double getDepBedCnt() {
		return depBedCnt;
	}

	public void setDepBedCnt(Double depBedCnt) {
		this.depBedCnt = depBedCnt;
	}

	public Double getDepDoctorCnt() {
		return depDoctorCnt;
	}

	public void setDepDoctorCnt(Double depDoctorCnt) {
		this.depDoctorCnt = depDoctorCnt;
	}


	public Double getIsOpeDep() {
		return isOpeDep;
	}

	public void setIsOpeDep(Double isOpeDep) {
		this.isOpeDep = isOpeDep;
	}
	
	public String getDepHisCode() {
		return depHisCode;
	}

	public void setDepHisCode(String depHisCode) {
		this.depHisCode = depHisCode;
	}

	public Integer getCountDRG() {
		return countDRG;
	}

	public void setCountDRG(Integer countDRG) {
		this.countDRG = countDRG;
	}

	@Override
	public Serializable getId() {
		return depCode;
	}


	@Override
	public String[] businessKeys() {
		return null;
	}
	
	/**
	 * 
	 * @methodname    :findDepCodeByName
	 * @description   :根据科室名称查询科室代码
	 * @param         :
	 * @author        :liqingyang
	 * @return        :
	 * @date          :2015年5月19日
	 */
	public static String findDepCodeByName(String depName){
		String depCodeString = "";
		List<Object> list = getRepository()
				.createNamedQuery("Department.findDepCodeByName")
				.addParameter("depName", depName)
				.list();
		if(list.size()>0){
			depCodeString = list.get(0).toString();
		}
		return depCodeString;
	}
	/**
	 * 
	 * @methodname    :findDepNameByCode
	 * @description   : 根据科室名称查询科室名称
	 * @param         :
	 * @author        :mazhaoyan
	 * @return        :
	 * @date          :2016年12月23日
	 */
	public static String findDepNameByCode(String depCode){
		String depName = "";
		List<Object> list = getRepository()
				.createNamedQuery("Department.findDepNameByCode")
				.addParameter("depCode", depCode)
				.list();
		if(list.size()>0){
			depName = list.get(0).toString();
		}
		return depName;
	}
}
